﻿using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.IO;
using System.Web;

namespace Framework.Library.Core.Utils.Images
{
    public class ImagesUtils
    {
        public static string GetImage(string urlPath, int width)
        {
            return GetImage(urlPath, width, 0);
        }

        public static string GetImage(string urlPath, int width, int height)
        {
            return GetImage(urlPath, width, height, false);
        }

        public static string GetImage(string urlPath, int width, int height, bool crop)
        {
            return GetImage(urlPath, width, height, crop, string.Empty);
        }

        public static string GetImage(string urlPath, int width, int height, bool crop, string background)
        {
            if(width > 0)
            {
                string imageFormat = urlPath + "?w=" + width;
                if(height > 0)
                {
                    imageFormat += imageFormat + "&h=" + height;
                    if(crop)
                        imageFormat += imageFormat + "&crop=auto";
                    if(!string.IsNullOrEmpty(background))
                        imageFormat += imageFormat + "&bgcolor=" + background;
                }
                return imageFormat;
            }
            else
                return urlPath;
        }
    }
}